package com.oocl.euc.core.attachment.repository;

import com.oocl.euc.core.attachment.model.Attachment;
import com.oocl.euc.core.builder.AttachmentBuilder;
import com.oocl.euc.core.common.ITTestBase;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static org.junit.Assert.*;

public class AttachmentRepositoryIT extends ITTestBase {

    @Autowired
    AttachmentBuilder attachmentBuilder;

    @Autowired
    AttachmentRepository attachmentRepository;

    @After
    public void tearDown() throws Exception {
        attachmentRepository.deleteAll();
    }

    @Test
    public void should_return_one_attachment_when_given_one_md5_code() {
        Attachment attachment = attachmentBuilder.defaultBuilder()
                .withMd5Code("TEST MD5 CODE")
                .saveToDB();
        List<Attachment> attachments = attachmentRepository.findByMd5Code(attachment.getMd5Code());
        assertTrue(attachments.size() > 0);
        assertEquals("TEST MD5 CODE", attachments.get(0).getMd5Code());
    }
}